//
//  AudioCollectionViewController.m
//  To Feel
//
//  Created by 于成哲 on 16/7/23.
//  Copyright © 2016年 caoyu. All rights reserved.
//

#import "AudioCollectionViewController.h"
#import "ModelOfAudioClassify.h"
#import "CellOfAudio.h"
#import "ProgramTableViewController.h"
@interface AudioCollectionViewController ()
@property (nonatomic ,retain) NSMutableArray *arrForList;
@end

@implementation AudioCollectionViewController

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];

}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.collectionView reloadData];
}
- (void)setArrOfList:(NSArray *)arrOfList {
    if (_arrForList != arrOfList) {
        _arrOfList = arrOfList;
    }
    self.arrForList = [NSMutableArray array];
    for (NSDictionary *dic in arrOfList) {
        ModelOfAudioClassify *model = [[ModelOfAudioClassify alloc] init];
        [model setValuesForKeysWithDictionary:dic];
        [self.arrForList addObject:model];
    }
    
    
    [self.collectionView registerClass:[CellOfAudio class] forCellWithReuseIdentifier:@"pool3"];
    
    self.collectionView.backgroundColor = [UIColor whiteColor];
    
    [self.collectionView reloadData];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.arrForList.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CellOfAudio *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool3" forIndexPath:indexPath];
    cell.model = [self.arrForList objectAtIndex:indexPath.item];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dic = [self.arrOfList objectAtIndex:indexPath.row];
    
    ProgramTableViewController *program = [[ProgramTableViewController alloc] init];
    [self.navigationController pushViewController:program animated:YES];
    program.urlString = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/v1/album?albumId=%@&device=android&isAsc=true&pageId=1&pageSize=20&pre_page=0&source=4&statEvent=pageview2Falbum404805355&statModule=E5%90%ACE8B584E8AEAF&statPage=tab40E58F91E78EB0_E68EA8E88D90&statPosition=1&trackId=18869179", dic[@"albumId"]];
    
}
@end
